<template>
  <a-modal :open="open" width="700px" title="解除隔离" centered ok-text="保存" @ok="onOk" @cancel="onCancel">
    <a-form class="form-style-flex" name="validate_other" :model="formState" :label-col="{ style: { width: '110px' } }">
      <a-form-item label="解除日期" class="w-1/2">
        <a-date-picker v-model:value="formState.unsealTime" format="YYYY-MM-DD " value-format="YYYY-MM-DD" />
      </a-form-item>
      <a-form-item label="解除隔离原因" class="w-full mb-3">
        <a-textarea v-model:value="formState.unsealReason" :rows="5" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import dayjs from 'dayjs'
import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'update:value', 'success'])

const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})

const formState = ref({})

const onOk = async () => {
  const { code, msg } = await post('/war/epidemicPrevention/doSaveEpidemicIsolate', {
    ...formState.value,
    id: props.rowData.isolateId,
    bedId: props.rowData.bedId
  })
  if (code !== 0) return message.error(msg)
  message.success(msg)
  emit('update:open', false)
  emit('success')
}

const onCancel = () => {
  emit('update:open', false)
}

watch(
  () => props.open,
  (val) => {
    if (val) {
      formState.value = {
        unsealTime: dayjs().format('YYYY-MM-DD'),
        unsealReason: ''
      }
    }
  }
)
</script>
<style lang="less" scoped></style>
